package com.yx.backstage.manager;

import org.springframework.stereotype.Component;

/**
 * @author YangXiong
 */
@Component
public class LoginOrRegisterManager {

//    public CommonResult login(HttpServletResponse response, HttpServletRequest request, LoginOrRegisterParam param) {
//        response.setCharacterEncoding("UTF-8");
//        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(User::getUserId, param.getUserId());
//        User user = userService.getOne(queryWrapper);
//        if (ObjectUtil.isEmpty(user)) {
//            throw new BizException("账号不存在,请输入正确的账号~~~");
//        } else if (!(user.getUserName().equals(param.getUserName()))) {
//            throw new BizException("用户名不正确,请输入正确的用户名~~~");
//        } else if (!(user.getPassword().equals(param.getPassword()))) {
//            throw new BizException("密码不正确,请输入正确的密码~~~");
//        }
//        request.getSession().setAttribute(user.getUserId() + "", user);
//        response.addCookie(new Cookie(user.getUserId() + "", JSON.toJSONString(user.getUserId() + user.getUserName() + user.getPassword())));
//        return CommonResult.success("登录成功~~~");
//    }
//
//    public CommonResult register(LoginOrRegisterParam param) {
//        User user = new User();
//        BeanUtil.copyProperties(param, user);
//        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(User::getUserId, param.getUserId());
//        User userTmp = userService.getOne(queryWrapper);
//        if (ObjectUtil.isNotEmpty(userTmp)) {
//            throw new BizException("该账号已经存在了~~~");
//        }
//        userService.save(user);
//        return CommonResult.success("注册成功~~~");
//    }
}
